home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / ada_tutr.zip / PRINT.ME < prev    next >
Text File  |  1994-08-22  |  87KB  |  2,215 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.                               Welcome  to
  21.                             A D A - T U T R
  22.                        The Interactive Ada Tutor
  23.                         by John J. Herro, Ph.D.
  24.                     Software Innovations Technology
  25.  
  26.                   These are the printed course notes.
  27.  
  28.                         Ver. 3.00, 22 Aug. 1994
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.                    Copyright 1988-1994 John J. Herro
  42.  
  43.                     Software Innovations Technology
  44.              1083 Mandarin Dr. NE, Palm Bay, FL 32905-4706
  45.                              (407)951-0233
  46.  
  47.             Internet: john.herro@p2.f38.n374.z1.fidonet.org
  48.  
  49.                           Fidonet: 1:374/38.2
  50.  
  51.  
  52.                   You may make copies of these notes,
  53.                   in printed or machine-readable form.
  54.  
  55.                 You may also copy the computer program.
  56.                      Please see page 1 for details.
  57.  
  58.  
  59.                                                                Page  i
  60.  
  61.                           TABLE OF CONTENTS
  62.  
  63.  
  64. Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   i
  65. Acknowledgments  . . . . . . . . . . . . . . . . . . . . . . . . .  ii
  66. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . .   1
  67. Registration and Licenses - What is Shareware? . . . . . . . . . .   2
  68. Special Offer to Companies, Schools, Etc.  . . . . . . . . . . . .   3
  69. Note to Compiler Companies . . . . . . . . . . . . . . . . . . . .   5
  70. Does Your Screen Show Strange Characters Like Arrows and Brackets?   6
  71. The Ada Reserved Words . . . . . . . . . . . . . . . . . . . . . .   7
  72. Steps for Outside Assignment 1, Preparing to Run Ada . . . . . . .   8
  73. Listings of HELLO.ADA and ADD.ADA  . . . . . . . . . . . . . . . .   9
  74. Listing of TRITEST.ADA . . . . . . . . . . . . . . . . . . . . . .  10
  75. Steps for Outside Assignment 2, Exercise in Enumeration Types  . .  12
  76. Listing of NEXTDATE.ADA  . . . . . . . . . . . . . . . . . . . . .  13
  77. Steps for Outside Assignment 3, Exercise in Records  . . . . . . .  14
  78. Listing of FIBTEST.ADA . . . . . . . . . . . . . . . . . . . . . .  15
  79. Steps for Outside Assignment 4, Exercise in Recursion  . . . . . .  16
  80. Simplified Specification for TEXT_IO . . . . . . . . . . . . . . .  17
  81. Listings of Procedure FILECOPY and Function EXISTS . . . . . . . .  19
  82. Requirements for the Program LEDIT . . . . . . . . . . . . . . . .  20
  83. Steps for Outside Assignment 5, Writing a Simple Line Editor . . .  25
  84. How to Test LEDIT  . . . . . . . . . . . . . . . . . . . . . . . .  26
  85. Listing of LEDIT.ANS . . . . . . . . . . . . . . . . . . . . . . .  29
  86. Listing of TASKING.DUM . . . . . . . . . . . . . . . . . . . . . .  33
  87. Steps for Outside Assignment 6, Exercise in Tasking  . . . . . . .  34
  88. Output from TASKING.EXE After Modification of TASKING.ADA  . . . .  35
  89. Listing of TASKING.ANS . . . . . . . . . . . . . . . . . . . . . .  36
  90.  
  91. Appendix A:  Would You Like a Textbook to Use Along with ADA-TUTR?  37
  92. Appendix B:  Running BOOK to Print All the Screens . . . . . . . .  38
  93. Appendix C:  Some Ada Compilers Available for the PC . . . . . . .  39
  94. Appendix D:  Sample Multi-User Software License  . . . . . . . . .  40
  95. Appendix E:  Installing ADA-TUTR on Other Computers  . . . . . . .  42
  96. Appendix F:  We Listen!  New Features of ADA-TUTR  . . . . . . . .  47
  97. Appendix G:  Disclaimer of Warranty  . . . . . . . . . . . . . . .  49
  98.  
  99.                                                                Page ii
  100.  
  101.                            ACKNOWLEDGMENTS
  102.  
  103. The following trademarks are used in these notes and in the
  104. accompanying files:
  105.  
  106.         FirstAda         Alsys, Inc.
  107.         IBM              International Business Machines Corp.
  108.         IntegrAda        Aetech, Inc.
  109.         Janus/Ada        R R Software, Inc.
  110.         Meridian Ada     Meridian Software Systems, Inc.
  111.         Open Ada         Meridian Software Systems, Inc.
  112.         TeleGen          Telesoft Corporation
  113.         Turbo Pascal     Borland International
  114.         UNIX             AT & T
  115.         VAX              Digital Equipment Corporation
  116.         VMS              Digital Equipment Corporation
  117.  
  118. The file ONECHAR.C was sent to us by Mr. David Hill, 7549 Wynford
  119. Street, Salt Lake City, UT 84121, and the file ALTCHAR.C was sent to
  120. us by Mr. Richard Conn, 22 Hunt Court, Tinton Falls, NJ 07753.  We're
  121. very grateful to Mr. Hill and to Mr. Conn for giving us permission to
  122. include these files in ADA-TUTR.  When used with UNIX.ADA, these files
  123. provide two ways to run the Tutor on UNIX based machines without
  124. having to strike ENTER after each response.  See pages 42-46.
  125.  
  126. The programs in this version of ADA-TUTR were compiled with the
  127. Meridian Ada Compiler, v4.1, and optimized with the Meridian IFORM
  128. Optimizer, v1.0.  The .EXE files contain Meridian's runtime, and were
  129. compressed with the public domain program LZEXE, v0.91, by Fabrice
  130. Bellard of Grabels, France.
  131.  
  132.                                                                Page  1
  133.  
  134.                              INTRODUCTION
  135.  
  136. ADA-TUTR, the Interactive Ada Tutor, will make you an excellent Ada
  137. programmer in minimum time.  You'll learn good Ada program design
  138. techniques, not just Ada syntax.  ADA-TUTR runs on PCs as well as
  139. workstations and mainframes.  On PCs an Ada compiler is helpful, but
  140. not required.  The PC can have any monochrome or color monitor.
  141.  
  142. These printed notes aren't meant to be a complete course, or even a
  143. summary, of Ada.  They merely accompany the program ADA-TUTR, which is
  144. a complete course.  You can't "study" these printed notes alone.  For
  145. now, just read pages 1, 2, and 6.
  146.  
  147. ADA-TUTR lets you learn at your own pace.  So that you don't feel
  148. pressured, ADA-TUTR doesn't keep track of the number of right and
  149. wrong answers.  It simply tells you whether your answers are correct,
  150. and why.  Also, there's no time limit for answering the questions or
  151. completing the Outside Assignments.
  152.  
  153. Because I want every programmer to have a chance to learn the best
  154. programming language, I made ADA-TUTR available very inexpensively as
  155. Shareware.  Shareware isn't the same as public domain, and ADA-TUTR
  156. isn't free.  But you may TRY it for free, and register or buy a
  157. license only if you use it.  Please see pages 2-3 for details.
  158.  
  159. Whether or not you use ADA-TUTR and register (or buy a license),
  160. please make unmodified copies of the program and distribute them on
  161. computer bulletin boards, at club meetings, and give them to schools,
  162. companies, etc.  You may charge a small fee to copy the program,
  163. provided you make it clear that the fee is only for the copy, and
  164. doesn't pay for the Shareware.  (Companies that copy Shareware usually
  165. charge about $2 to $10 per diskette.)  Bulletin boards may carry
  166. ADA-TUTR even if they charge for access, and you may include ADA-TUTR
  167. on CD-ROMs.  Please contact us for permission to include ADA-TUTR with
  168. other commercial products, such as Ada compilers (see page 5).  You
  169. may use file compression programs on ADA-TUTR; we won't interpret that
  170. as "modifying" the program.  You may also add your own files.  (The
  171. files included with ADA-TUTR are briefly described in FILES.LST.)  If
  172. you register, you can earn substantial money distributing ADA-TUTR;
  173. please see page 2 for details.
  174.  
  175. Ada will become more and more important, since the Department of
  176. Defense mandated its use in defense software, and is now making it
  177. very hard to obtain waivers.  Although learning Ada takes real effort,
  178. you'll be able to write software that's more reliable and easier to
  179. modify a month or a year later.
  180.  
  181. New features of this version of ADA-TUTR are described on pages 47-48.
  182. Please send me your comments and suggestions.  I wish you success
  183. using ADA-TUTR!
  184.  
  185. John J. Herro, Ph.D., Software Innovations Technology
  186. 1083 Mandarin Drive NE, Palm Bay, FL 32905-4706   (407)951-0233
  187.  
  188.                                                                Page  2
  189.  
  190.             REGISTRATION AND LICENSES - WHAT IS SHAREWARE?
  191.  
  192. Shareware is a way of marketing a program.  It lets you try the
  193. program before spending money for it.  If you decide to use the
  194. program, you send a small payment to register your copy or buy a
  195. license.  We give you several incentives to do so, explained below.
  196. You're on your honor; you know whether you're "using" ADA-TUTR or
  197. only "trying" it.
  198.  
  199. To use ADA-TUTR, individuals register as described below.  Companies,
  200. schools, and other organizations can register each individual who
  201. uses the program, or buy a Multi-User License as described on the next
  202. page.
  203.  
  204. INDIVIDUALS:  Register your copy for only $25.  When you register,
  205. please give us the serial number from the ADA-TUTR opening screen.
  206. We'll assign you a new serial number.  Then run CHANGESN to put your
  207. new number into the program, and give copies to individuals, schools,
  208. companies, clubs, computer bulletin boards, etc.
  209.  
  210. We'll send you a commission of $5 for each individual who registers
  211. from one of your copies, and TEN PERCENT for each Multi-User License
  212. sold from one of your copies!  As you can see from the next page, you
  213. can earn up to $240 per license sold!  Commissions are paid quarterly.
  214. If you like, print the file AD.TXT and use copies as an advertisement.
  215.  
  216. Registration includes the right to use ADA-TUTR as long as you like,
  217. and it includes technical support for one year.  While you have
  218. technical support, we'll inform you of any important updates to
  219. ADA-TUTR, and send you updated copies for only $5 each ($10 if you
  220. prefer a 3.5" diskette, free if you send us a formatted diskette with
  221. a stamped diskette mailer).  We're planning another update of ADA-TUTR
  222. some time after the Ada 9X definition is finalized.  You can renew
  223. technical support for only $10 a year.  Even if you don't renew,
  224. you'll continue to receive commissions.
  225.  
  226. When you register, you may order a copy of the current version of
  227. ADA-TUTR, with your serial number.  The price is $5 for a 5.25"
  228. diskette, $10 for a 3.5" diskette, or free with your formatted
  229. diskette and a stamped diskette mailer.  If you would like an order
  230. form or a price list, please print the file INVOICE.TXT.
  231.  
  232. We offer a Customization Kit that lets you edit, add, and delete
  233. ADA-TUTR screens, questions, etc. (even whole topics), producing a new
  234. ADA_TUTR.DAT file.  See the last paragraph on page 4.  Note that the
  235. Customization Kit is not Shareware.
  236.  
  237. We sell anywhere in the Free World.  We're sorry, but we don't yet
  238. accept credit cards.  Outside the U.S., please remit in U.S. funds and
  239. contact us about extra postal charges on diskettes.
  240.  
  241.  
  242. COMPANIES, SCHOOLS, AND OTHER ORGANIZATIONS:  Please see our special
  243. offer for Multi-User Licenses on the next page.
  244.  
  245.                                                                Page  3
  246.  
  247.                SPECIAL OFFER TO COMPANIES, SCHOOLS, ETC.
  248.  
  249. ADA-TUTR can be of great benefit to your company, school, or other
  250. organization.  We encourage you to try ADA-TUTR before paying for it,
  251. and you may install ADA-TUTR on your workstations and mainframes as
  252. well as your PCs!  Instructions for installing ADA-TUTR on other
  253. computers are on page 42.
  254.  
  255. If you decide to use ADA-TUTR, you could register each individual
  256. user, as described on page 2.  But if you have more than 18 users, you
  257. can save money by buying a Multi-User License, as described here.
  258. You're on your honor; you know whether you're "using" ADA-TUTR or only
  259. "trying" it.  Multi-User Licenses are very reasonably priced, as
  260. follows:
  261.  
  262.  Number of Users:  Price of License:               Note:
  263.  
  264.     Up to  100        only  $450      Send $5 extra for a copy of the
  265.     Up to  500        only  $725      latest version of ADA-TUTR on a
  266.     Up to 2000        only  $950      5.25" diskette, $10 extra for a
  267.     Unlimited         only $2400      copy on a 3.5" diskette.
  268.  
  269. A license may always be upgraded for only the difference in price.
  270.  
  271. A sample Multi-User license appears on pages 40-41.  A Multi-User
  272. License gives the specified number of people the right to use ADA-TUTR
  273. as long as you like, on all your computers (from small PCs to large
  274. mainframes), at all your locations.  We use the term Multi-User
  275. License rather than Site License because there are no geographic
  276. restrictions.  (Note: If 100 people use ADA-TUTR now and 100 others
  277. use it later, that counts as 200 users, not 100.)  Sales commissions
  278. are NOT paid to Multi-User Licensees.
  279.  
  280. A Multi-User License includes one year of technical support, which can
  281. be renewed for only 10% of the price of the license per year.  While
  282. you have technical support, we'll inform you of any important updates
  283. to ADA-TUTR, and send you an updated copy on a 5.25" diskette for only
  284. $5 ($10 for a 3.5" diskette).  The update is free if you send a
  285. formatted diskette and a stamped diskette mailer.  We're planning
  286. another update of ADA-TUTR some time after the Ada 9X definition is
  287. finalized.
  288.  
  289. Even if you don't renew your Technical Support, you'll still have the
  290. right to use ADA-TUTR as long as you like.
  291.  
  292. Please print the file INVOICE.TXT, or use your own form.  (When
  293. ordering, please give us the serial number from the opening screen of
  294. your copy of ADA-TUTR, if you have one.)
  295.  
  296. We accept Purchase Orders.  Our Federal tax ID number is 360-40-8382,
  297. and we qualify as a Small Business.  We sell anywhere in the Free
  298. World.  We're sorry, but we don't yet accept credit cards.  Outside
  299. the U.S., please remit in U.S. funds and contact us about extra postal
  300. charges on diskettes.
  301.  
  302.                                                                Page  4
  303.  
  304. With Shareware, you never have to worry about software piracy, because
  305. your people are ENCOURAGED to copy and distribute the program!  If you
  306. prefer, however, a non-Shareware version of ADA-TUTR is available at
  307. the same prices.
  308.  
  309. If you buy a license, we'll be happy to do minor customization of
  310. ADA-TUTR for you at no charge.  For example, we can add your company
  311. name to the opening screen.  If you'd like major customization,
  312. contact us for terms, or buy our Customization Kit for $195.  Using
  313. any text editor on a PC, workstation, or mainframe, the Customization
  314. Kit lets you edit, add, and delete screens, questions, etc. (even
  315. whole topics), producing a new ADA_TUTR.DAT file.  The Customization
  316. Kit isn't Shareware, but you may copy it for use throughout your
  317. organization as required.
  318.  
  319.                                                                Page  5
  320.  
  321.                       NOTE TO COMPILER COMPANIES
  322.  
  323. A special version of ADA-TUTR is available, without the Shareware
  324. notices and without the list of Ada compilers.  It can be customized
  325. for your company, and can run on almost any Ada platform, including
  326. workstations and mainframes, because Ada source code is included.
  327. ADA-TUTR can greatly increase the sales appeal of your compilers and
  328. your Ada tools, whether you sell it separately or include it with your
  329. products.  Please contact us.
  330.  
  331. If you're a prospective contractor or subcontractor, the Shareware or
  332. special version of ADA-TUTR may be the best and most economical way
  333. for you to supply your customer's Ada educational needs.  Please
  334. contact us before writing your proposal.
  335.  
  336.                                                                Page  6
  337.  
  338.   DOES YOUR SCREEN SHOW STRANGE CHARACTERS LIKE ARROWS AND BRACKETS?
  339.  
  340. Give the command TYPE READ.ME on your PC.  If one word appears
  341. brighter than the rest, you can skip this page.  However, if your
  342. screen shows strange characters like "[1m" when you TYPE READ.ME or
  343. run ADA_TUTR, you need to read this.
  344.  
  345. ADA-TUTR uses ANSI (American National Standards Institute) escape
  346. sequences for highlighting, cursor positioning, reverse video, etc.
  347. Before ADA-TUTR will work correctly on a PC, you must install the
  348. device driver ANSI.SYS, which came with your copy of DOS.  To install
  349. ANSI.SYS, do the following:
  350.  
  351. 1.  If there's a file CONFIG.SYS in the root directory of the disk
  352.     from which you boot, type it and look for a line saying
  353.     "DEVICE=ANSI.SYS" (without the quotes), in either upper or lower
  354.     case.  If that line is not present, add it to CONFIG.SYS anywhere
  355.     in the file, using an ordinary text editor or word processor in
  356.     the non-document mode.  If there's no CONFIG.SYS file, create one
  357.     containing the single line "DEVICE=ANSI.SYS" (without the quotes).
  358.  
  359. 2.  If there's no file ANSI.SYS in your root directory, copy ANSI.SYS
  360.     from your DOS distribution diskette to the root directory of the
  361.     disk from which you boot.
  362.  
  363. 3.  Reboot the computer.  ADA-TUTR should then work correctly.
  364.  
  365.                                                                Page  7
  366.  
  367.                        THE ADA RESERVED WORDS
  368.  
  369. The reserved words are listed in the Language Reference Manual in
  370. section 2.9, and are repeated here for convenience.
  371.  
  372.   abort         declare        generic      of             select
  373.   abs           delay          goto         or             separate
  374.   abstract *    delta                       others         subtype
  375.   accept        digits                      out
  376.   access        do             if
  377.   aliased *                    in                          tagged *
  378.   all                          is           package        task
  379.   and                                       pragma         terminate
  380.   array                                     private        then
  381.   at                                        procedure      type
  382.                 else           limited      protected *
  383.                 elsif          loop
  384.                 end                                        until *
  385.                 entry                                      use
  386.   begin         exception                   raise
  387.   body          exit           mod          range
  388.                                             record         when
  389.                                             rem            while
  390.                                             renames        with
  391.                                new          requeue *
  392.   case          for            not          return
  393.   constant      function       null         reverse        xor
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. * Ada 9X only.
  401.  
  402.                                                                Page  8
  403.  
  404.          STEPS FOR OUTSIDE ASSIGNMENT 1, PREPARING TO RUN ADA
  405.  
  406. For the first Outside Assignment, learn enough about your Ada compiler
  407. to compile and run the two simple programs HELLO.ADA and ADD.ADA.
  408. Obviously, you have to do this before you can do the remaining Outside
  409. Assignments.
  410.  
  411. 1.  Compile HELLO.ADA.  On most systems, after the Ada compiler is
  412. installed and your library is created, this only involves typing
  413. ADA HELLO or ADA HELLO.ADA.  On some systems, the compiler is invoked
  414. from a menu or "APSE" (Ada Programming Support Environment).
  415.  
  416. 2.  Link, giving the name of the main program, HELLO.  This usually
  417. involves typing LINK HELLO or BIND HELLO, perhaps with some options.
  418. On one system, the command is BAMP HELLO, for Build Ada Main Program!
  419.  
  420. 3.  Run the program.  If your Ada compiler produces native code on a
  421. PC, it created a file HELLO.EXE, and this step simply involves typing
  422. HELLO.  On other systems, the command RUN HELLO is appropriate.  On
  423. some systems, you have to invoke an interpreter to run the program.
  424.  
  425. 4.  Now compile, link, and run ADD.ADA.
  426.  
  427. If your compiler implements a subset of Ada, you may have to modify
  428. the programs in this and later Outside Assignments to get them to
  429. compile.  Some subset Ada compilers don't allow "separate" compilation
  430. (used in later assignments), and you'll have to include the "separate"
  431. subprograms inside the main program and compile them as one.  Some
  432. subset compilers don't allow generic instantiation, and have another
  433. way of displaying integers.  In that case, you'll have to modify
  434. ADD.ADA.  If you're using a validated compiler, you won't have to
  435. worry about any of this, because all of the Outside Assignments are
  436. written in standard Ada.
  437.  
  438.                                                                Page  9
  439.  
  440. HELLO.ADA
  441. ---------
  442.  
  443. with Text_IO; use Text_IO;
  444. procedure Hello is
  445. begin
  446.    Put_Line("Hello!");
  447. end Hello;
  448.  
  449.  
  450.  
  451. ADD.ADA
  452. -------
  453.  
  454. with Text_IO; use Text_IO;
  455. procedure Add is
  456.    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  457. begin
  458.    Put(2 + 2);
  459.    New_Line;
  460. end Add;
  461.  
  462.                                                                Page 10
  463.  
  464. TRITEST.ADA
  465. -----------
  466.  
  467. with Text_IO; use Text_IO;
  468. procedure Tritest is
  469.    Passed : Boolean := True;
  470.    type Triangle is (Equilateral, Isosceles, Scalene, Not_a_Triangle);
  471.    function Tritype(Len1, Len2, Len3 : in Integer) return Triangle
  472.                                                           is separate;
  473.    procedure Compare(A, B, C: in Integer; Right_Answer : in Triangle)
  474.                                                           is separate;
  475. begin
  476.    Compare( 3,  4,  5, Scalene);
  477.    Compare( 6,  3,  4, Scalene);
  478.    Compare( 4,  3,  6, Scalene);
  479.    Compare( 3,  3,  3, Equilateral);
  480.    Compare( 3,  3,  4, Isosceles);
  481.    Compare( 3,  4,  3, Isosceles);
  482.    Compare( 4,  3,  3, Isosceles);
  483.    Compare( 7,  7,  4, Isosceles);
  484.    Compare( 7,  4,  7, Isosceles);
  485.    Compare( 4,  7,  7, Isosceles);
  486.    Compare( 1,  1,  1, Equilateral);
  487.    Compare( 0,  4,  4, Not_a_Triangle);
  488.    Compare( 4,  0,  4, Not_a_Triangle);
  489.    Compare( 4,  4,  0, Not_a_Triangle);
  490.    Compare( 0,  4,  3, Not_a_Triangle);
  491.    Compare( 3,  0,  4, Not_a_Triangle);
  492.    Compare( 4,  3,  0, Not_a_Triangle);
  493.    Compare(-1,  4,  4, Not_a_Triangle);
  494.    Compare( 4, -1,  4, Not_a_Triangle);
  495.    Compare( 4,  4, -1, Not_a_Triangle);
  496.    Compare(-1,  4,  3, Not_a_Triangle);
  497.    Compare( 3, -1,  4, Not_a_Triangle);
  498.    Compare( 4,  3, -1, Not_a_Triangle);
  499.    Compare( 2,  4,  6, Not_a_Triangle);
  500.    Compare( 1,  3,  2, Not_a_Triangle);
  501.    Compare( 3,  1,  2, Not_a_Triangle);
  502.    Compare( 1,  2,  4, Not_a_Triangle);
  503.    Compare( 1,  4,  2, Not_a_Triangle);
  504.    Compare( 4,  1,  2, Not_a_Triangle);
  505.    Compare( 0,  0,  0, Not_a_Triangle);
  506.    Compare( 0,  0,  4, Not_a_Triangle);
  507.    Compare( 0,  4,  0, Not_a_Triangle);
  508.    Compare( 4,  0,  0, Not_a_Triangle);
  509.    Compare( 3,  3,  7, Not_a_Triangle);
  510.    Compare( 3,  7,  3, Not_a_Triangle);
  511.    Compare( 6,  3,  3, Not_a_Triangle);
  512.    Compare(-3, -4, -5, Not_a_Triangle);
  513.    if Passed then
  514.       Put_Line("Congratulations, you completed the assignment!");
  515.    end if;
  516. end Tritest;
  517.                            -- continued --
  518.  
  519.                                                                Page 11
  520.  
  521. separate (Tritest)
  522. procedure Compare(A, B, C: in Integer; Right_Answer : in Triangle) is
  523.    package Int_IO is new Integer_IO(Integer); use Int_IO;
  524.    package Tri_IO is new Enumeration_IO(Triangle); use Tri_IO;
  525.    My_Answer : Triangle := Tritype(A, B, C);
  526. begin
  527.    if My_Answer /= Right_Answer then
  528.       Put("Sides:");
  529.       Put(A, Width => 3);
  530.       Put(B, Width => 3);
  531.       Put(C, Width => 3);
  532.       Put("   My answer: ");
  533.       Put(My_Answer, Width => 14);
  534.       Put("   Right answer: ");
  535.       Put(Right_Answer);
  536.       New_Line;
  537.       Passed := False;
  538.    end if;
  539. end Compare;
  540.  
  541.                                                                Page 12
  542.  
  543.     STEPS FOR OUTSIDE ASSIGNMENT 2, EXERCISE IN ENUMERATION TYPES
  544.  
  545. 1.  Compile the test driver TRITEST.ADA.  Also, make a copy of the
  546.     dummy solution by typing COPY TRITYPE.DUM TRITYPE.ADA.  You need
  547.     do this step only once.
  548.  
  549. 2.  Edit TRITYPE.ADA to become your real solution.  You can skip this
  550.     step the first time through, to see error messages from the test
  551.     driver.
  552.  
  553. 3.  Compile your solution TRITYPE.ADA.  If the compiler finds errors,
  554.     go back to step 2.
  555.  
  556. 4.  Link with the name of the main program TRITEST.  Then execute.  If
  557.     the test driver displays error messages, go back to step 2.
  558.  
  559. 5.  When the message "Congratulations, you completed the assignment!"
  560.     is displayed, you'll have a chance to compare your solution with
  561.     ours.
  562.  
  563.                                                                Page 13
  564.  
  565. NEXTDATE.ADA
  566. ------------
  567.  
  568. with Text_IO; use Text_IO;
  569. procedure Nextdate is
  570.    type Month_Type is
  571.       (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
  572.    subtype Day_Subtype is Integer range 1 .. 31;
  573.    type Date is
  574.       record
  575.          Day   : Day_Subtype;
  576.          Month : Month_Type;
  577.          Year  : Positive;
  578.       end record;
  579.    Passed : Boolean := True;
  580.    function Tomorrow(Today : in Date) return Date is separate;
  581.  
  582.    procedure Display (S : in String; D : in Date) is
  583.       package Int_IO is new Integer_IO(Integer); use Int_IO;
  584.    begin
  585.       Put(S);
  586.       Put(D.Day, Width => 3);
  587.       Put(" " & Month_Type'Image(D.Month));
  588.       Put(D.Year, Width => 5);
  589.       New_Line;
  590.    end Display;
  591.    procedure Compare(Today, Right_Answer : in Date) is
  592.       My_Answer : Date := Tomorrow(Today);
  593.    begin
  594.       if My_Answer /= Right_Answer then
  595.          Display("Today:       ", Today);
  596.          Display("My answer:   ", My_Answer);
  597.          Display("Right answer:", Right_Answer);
  598.          New_Line;
  599.          Passed := False;
  600.       end if;
  601.    end Compare;
  602. begin
  603.    Compare((12,Dec,1815), (13,Dec,1815)); -- ordinary date
  604.    Compare(( 3,Feb,1986), ( 4,Feb,1986)); -- ordinary date in Feb.
  605.    Compare((30,Jun,1981), ( 1,Jul,1981)); -- last day of 30-day month
  606.    Compare((30,Sep,3999), ( 1,Oct,3999)); -- last day of 30-day month
  607.    Compare((31,Mar,1876), ( 1,Apr,1876)); -- last day of 31-day month
  608.    Compare((31,Aug,1984), ( 1,Sep,1984)); -- last day of 31-day month
  609.    Compare((31,Dec,1966), ( 1,Jan,1967)); -- last day of year
  610.    Compare((28,Feb,1980), (29,Feb,1980)); -- leap year
  611.    Compare((28,Feb,1600), (29,Feb,1600)); -- century leap year
  612.    Compare((28,Feb,2200), ( 1,Mar,2200)); -- century non-leap year
  613.    Compare((28,Feb,1982), ( 1,Mar,1982)); -- non-leap year
  614.    Compare((29,Feb,1980), ( 1,Mar,1980)); -- leap day in leap year
  615.    if Passed then
  616.       Put_Line("Congratulations, you completed the assignment!");
  617.    end if;
  618. end Nextdate;
  619.  
  620.                                                                Page 14
  621.  
  622.          STEPS FOR OUTSIDE ASSIGNMENT 3, EXERCISE IN RECORDS
  623.  
  624. 1.  Compile the test driver NEXTDATE.ADA.  Also, make a copy of the
  625.     dummy solution by typing COPY TOMORROW.DUM TOMORROW.ADA.  You need
  626.     do this step only once.
  627.  
  628. 2.  Edit TOMORROW.ADA to become your real solution.  You can skip this
  629.     step the first time through, to see error messages from the test
  630.     driver.
  631.  
  632. 3.  Compile TOMORROW.ADA.  If the compiler finds errors, go back to
  633.     step 2.
  634.  
  635. 4.  Link with the name of the main program NEXTDATE.  Then execute.
  636.     If the test driver displays error messages, go back to step 2.
  637.  
  638. 5.  When the message "Congratulations, you completed the assignment!"
  639.     is displayed, you'll have a chance to compare your solution with
  640.     ours.
  641.  
  642.                                                                Page 15
  643.  
  644. FIBTEST.ADA
  645. -----------
  646.  
  647. with Text_IO; use Text_IO;
  648. procedure Fibtest is
  649.    Passed : Boolean := True;
  650.    function Fib(N : in Positive) return Positive is separate;
  651.    procedure Compare (N : in Positive; Right_Answer : in Positive) is
  652.       package Int_IO is new Integer_IO(Integer); use Int_IO;
  653.       My_Answer : Positive := Fib(N);
  654.    begin
  655.       if My_Answer /= Right_Answer then
  656.          Put("N:");  Put(N);
  657.          Put("          My answer:");  Put(My_Answer);
  658.          Put("          Right answer:");  Put(Right_Answer);
  659.          New_Line;
  660.          Passed := False;
  661.       end if;
  662.    end Compare;
  663. begin
  664.    Compare(1, 1);
  665.    Compare(2, 1);
  666.    Compare(3, 2);
  667.    Compare(4, 3);
  668.    Compare(5, 5);
  669.    Compare(6, 8);
  670.    Compare(7, 13);
  671.    Compare(10, 55);
  672.    Compare(15, 610);
  673.    Compare(20, 6765);
  674.    if Passed then
  675.       Put_Line("Congratulations, you completed the assignment!");
  676.    end if;
  677. end Fibtest;
  678.  
  679.                                                                Page 16
  680.  
  681.         STEPS FOR OUTSIDE ASSIGNMENT 4, EXERCISE IN RECURSION
  682.  
  683. 1.  Compile the test driver FIBTEST.ADA.  Also, make a copy of the
  684.     dummy solution by typing COPY FIB.DUM FIB.ADA.  You need do this
  685.     step only once.
  686.  
  687. 2.  Edit FIB.ADA to become your real solution.  You can skip this step
  688.     the first time through, to see error messages from the test
  689.     driver.
  690.  
  691. 3.  Compile FIB.ADA.  If the compiler finds errors, go back to step 2.
  692.  
  693. 4.  Link with the name of the main program FIBTEST.  Then execute.  If
  694.     the test driver displays error messages, go back to step 2.
  695.  
  696. 5.  When the message "Congratulations, you completed the assignment!"
  697.     is displayed, you'll have a chance to compare your solution with
  698.     ours.
  699.  
  700.                                                                Page 17
  701.  
  702. SIMPLIFIED SPECIFICATION FOR TEXT_IO
  703. ------------------------------------
  704.  
  705. package Text_IO is
  706.    type File_Type is limited private;
  707.  
  708.    type File_Mode is (In_File, Out_File);  -- Ada 9X adds Append_File.
  709.    type Count is ... (a user-defined type similar to Integer);
  710.    Status_Error, Mode_Error, Name_Error, End_Error : exception;
  711.  
  712.    procedure Create      (File : in out File_Type;
  713.                           Mode : in File_Mode := Out_File;
  714.                           Name : in String);
  715.  
  716.    procedure Open        (File : in out File_Type;
  717.                           Mode : in File_Mode;
  718.                           Name : in String);
  719.  
  720.    procedure Close       (File : in out File_Type);
  721.    procedure Delete      (File : in out File_Type);
  722.    procedure New_Line    (Spacing : in Count := 1);
  723.    procedure New_Line    (File : in File_Type;
  724.                           Spacing : in Count := 1);
  725.    procedure Skip_Line   (Spacing : in Count := 1);
  726.    procedure Skip_Line   (File : in File_Type;
  727.                           Spacing : in Count := 1);
  728.    function  End_Of_File (File : in File_Type) return Boolean;
  729.    procedure Put         (Item : in Character);
  730.    procedure Put         (File : in File_Type; Item : in Character);
  731.    procedure Get         (Item : out Character);
  732.    procedure Get         (File : in File_Type; Item : out Character);
  733.    procedure Put         (Item : in String);
  734.    procedure Put         (File : in File_Type; Item : in String);
  735.    procedure Put_Line    (Item : in String);
  736.    procedure Put_Line    (File : in File_Type; Item : in String);
  737.    procedure Get_Line    (Item : out String; Last : out Natural);
  738.    procedure Get_Line    (File : in File_Type;
  739.                           Item : out String;
  740.                           Last : out Natural);
  741.    generic
  742.       type Num is range <>;
  743.    package Integer_IO is
  744.       procedure Get (Item : out Num);
  745.       procedure Get (File : in File_Type; Item : out Num);
  746.       procedure Put (Item  : in Num;
  747.                      Width : in Integer := ...;
  748.                      Base  : in Integer := 10);
  749.       procedure Put (File  : in File_Type;
  750.                      Item  : in Num;
  751.                      Width : in Integer := ...;
  752.                      Base  : in Integer := 10);
  753.    end Integer_IO;
  754.  
  755.                            -- continued --
  756.  
  757.                                                                Page 18
  758.  
  759.    generic
  760.       type Num is digits <>;
  761.    package Float_IO is
  762.       procedure Get (Item : out Num);
  763.       procedure Get (File : in File_Type; Item : out Num);
  764.       procedure Put (Item : in Num;
  765.                      Fore : in Integer := 2;
  766.                      Aft  : in Integer := ...;
  767.                      Exp  : in Integer := 3);
  768.       procedure Put (File : in File_Type;
  769.                      Item : in Num;
  770.                      Fore : in Integer := 2;
  771.                      Aft  : in Integer := ...;
  772.                      Exp  : in Integer := 3);
  773.    end Float_IO;
  774.  
  775.    generic
  776.       type Enum is (<>);
  777.    package Enumeration_IO is
  778.       procedure Get (Item : out Enum);
  779.       procedure Get (File : in File_Type; Item : out Enum);
  780.       procedure Put (Item : in Enum; Width : in Integer := 0);
  781.       procedure PUT (File : in File_Type;
  782.                      Item : in Enum; Width : in Integer := 0);
  783.    end Enumeration_IO;
  784.  
  785. private
  786.  
  787.    type File_Type is ... (implementation dependent);
  788.  
  789. end Text_IO;
  790.  
  791.                                                                Page 19
  792.  
  793. Program to copy a simple text file:
  794. -----------------------------------
  795.  
  796. with Text_IO; use Text_IO;
  797. procedure Filecopy Is
  798.    F1, F2 : File_Type;
  799.    S      : String(1 .. 80);
  800.    Len    : Integer;
  801. begin
  802.    Put("Input file: ");  Get_Line(S, Len);
  803.    Open(File => F1, Mode => In_File, Name => S(1 .. Len));
  804.    Put("Output file: ");  Get_Line(S, Len);
  805.    Create(File => F2, Mode => Out_File, Name => S(1 .. Len));
  806.    while not End_Of_File(F1) loop
  807.       Get_Line(F1, S, Len);
  808.       Put_Line(F2, S(1 .. Len));
  809.    end loop;
  810.    Close(F1);
  811.    Close(F2);
  812. end Filecopy;
  813.  
  814.  
  815.  
  816. Function to test if a text file exists:
  817. ---------------------------------------
  818.  
  819. with Text_IO; use Text_IO;
  820. function Exists(File_Name : in String) return Boolean Is
  821.    F      : File_Type;
  822.    Answer : Boolean := True;
  823. begin
  824.    begin
  825.       Open(F, In_File, File_Name);
  826.       Close(F);
  827.    exception
  828.       when Name_Error => Answer := False;
  829.    end;
  830.    return Answer;
  831. end Exists;
  832.  
  833.                                                                Page 20
  834.  
  835.                  REQUIREMENTS FOR THE PROGRAM LEDIT
  836.  
  837. This assignment will give you practice in writing a program of greater
  838. complexity than the previous programs you've written.  Imagine that
  839. your screen editor is unavailable to a particular user, perhaps
  840. because the user is dialing your computer from a remote location, and
  841. your screen editor writes directly to the screen.  You want to write a
  842. very simple line editor, LEDIT, that could be used in such
  843. circumstances.  While your computer already has a line editor called
  844. EDLIN, it's difficult to learn to use.  LEDIT will take almost no
  845. effort to learn.  The only commands are LIST and EXIT!  The line
  846. editor edits by means of line numbers, similar to the Basic language.
  847.  
  848. The user begins each typed line of text with a line number from 1 to
  849. 29999.  Line numbers must be integers.  The upper limit 29999 was
  850. chosen so that the simple type Integer could be used - in any
  851. implementation of Ada.   Regardless of the order in which lines are
  852. typed, LEDIT maintains a linked list of lines in order by number.
  853. Also, line numbers may be preceded by any number of spaces.  For
  854. example, if the user types
  855.  
  856. 40 -- This is a comment.
  857.    20 begin
  858. 10 with Text_IO; use Text_IO;
  859.       30 end Add;
  860.  
  861. and then types LIST, the editor will type
  862.  
  863.    10 with Text_IO; use Text_IO;
  864.    20 begin
  865.    30 end Add;
  866.    40 -- This is a comment.
  867.  
  868. To INSERT lines, the user merely types lines with intermediate line
  869. numbers.  For example, if the user types
  870.  
  871. 15 procedure Hello is
  872.  
  873. and then types LIST, LEDIT will type
  874.  
  875.    10 with Text_IO; use Text_IO;
  876.    15 procedure Hello is
  877.    20 begin
  878.    30 end Add;
  879.    40 -- This is a comment.
  880.  
  881. To REPLACE an existing line, the user merely types a line with the
  882. same line number as the line to be replaced.  For example, if
  883.  
  884. 15 procedure Add is
  885. LIST
  886.  
  887.  
  888.                            -- continued --
  889.  
  890.                                                                Page 21
  891.  
  892. is typed, LEDIT would then show
  893.  
  894.    10 with Text_IO; use Text_IO;
  895.    15 procedure Add is
  896.    20 begin
  897.    30 end Add;
  898.    40 -- This is a comment.
  899.  
  900. Finally, to DELETE a line, the user merely types the number of the
  901. line to be deleted, followed immediately by a carriage return.  Typing
  902.  
  903. 40
  904. LIST
  905.  
  906. would then produce
  907.  
  908.    10 with Text_IO; use Text_IO;
  909.    15 procedure Add is
  910.    20 begin
  911.    30 end Add;
  912.  
  913. Thus the user can INSERT, REPLACE, and DELETE lines, all by line
  914. numbers, without learning any commands.  Note that in this simple
  915. editor there is no "cursor" and no "current line."
  916.  
  917. The space is not required after the line number.  These two lines have
  918. exactly the same effect:
  919.  
  920. 20 begin
  921. 20begin
  922.  
  923. Of course, if the text of the line begins with a digit, a space will
  924. be required to separate it from the line number.  In any event, LEDIT
  925. always leaves one blank space after the line number when LISTing, for
  926. readability.  It always allows exactly five spaces for the line number
  927. itself.
  928.  
  929. However, any EXTRA spaces typed after the line number are significant.
  930. The three lines below each contain three EXTRA spaces after the line
  931. number, for a total of four spaces.
  932.  
  933. 24    Put(2 + 2);
  934. 26    New_LiNe;
  935. 18    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  936.  
  937. They have the effect of indenting the text three spaces.  LIST now
  938. shows
  939.  
  940.  
  941.                            -- continued --
  942.  
  943.                                                                Page 22
  944.  
  945.    10 with Text_IO; use Text_IO;
  946.    15 procedure Add is
  947.    18    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  948.    20 begin
  949.    24    Put(2 + 2);
  950.    26    New_Line;
  951.    30 end Add;
  952.  
  953. Although typing a line number followed immediately by a carriage
  954. return deletes a line (if there is a line by that number), typing a
  955. line number followed by a single space causes an empty line to be
  956. introduced into the file.  For example, typing 12 followed by a single
  957. space and a carriage return would then cause LIST to type
  958.  
  959.    10 with Text_IO; use Text_IO;
  960.    12
  961.    15 procedure Add is
  962.    18    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  963.    20 begin
  964.    24    Put(2 + 2);
  965.    26    New_Line;
  966.    30 end Add;
  967.  
  968. When LEDIT is run, it prompts for the names of the input and output
  969. files.  If the input file exists, LEDIT displays "File found" and
  970. reads the file into its linked list, assigning line numbers starting
  971. with 10 and incrementing by 10.  If the file does not exist, LEDIT
  972. displays "File not found," and the linked list is initially empty.  In
  973. any event, LEDIT creates an output file.  When the EXIT command is
  974. given, LEDIT writes the contents of the linked list to the output
  975. file.  In doing so, LEDIT removes the line numbers and the first blank
  976. after each line number.
  977.  
  978. In the example above, let's assume that the user typed ADD.ADA for an
  979. output file name.  When the user types EXIT, the new file ADD.ADA
  980. created by LEDIT will contain:
  981.  
  982. with Text_IO; use Text_IO;
  983.  
  984. procedure Add is
  985.    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  986. begin
  987.    Put(2 + 2);
  988.    New_Line;
  989. end Add;
  990.  
  991. (Note that the file contains one empty line.)  Your program is not
  992. allowed to add any trailing blanks of its own in the output file.  If
  993. the user again runs LEDIT and specifies ADD.ADA as an input file, the
  994. editor will type "File found" and read the file.  LIST will then show
  995.  
  996.  
  997.                            -- continued --
  998.  
  999.                                                                Page 23
  1000.  
  1001.    10 with Text_IO; use Text_IO;
  1002.    20
  1003.    30 procedure Add is
  1004.    40    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  1005.    50 begin
  1006.    60    Put(2 + 2);
  1007.    70    New_Line;
  1008.    80 end Add;
  1009.  
  1010. When the user EXITs, the new file will contain modified text.  The old
  1011. file will still be present until it is deleted.
  1012.  
  1013. The two commands LIST and EXIT must be accepted in either upper or
  1014. lower case, but for simplicity, they need not be accepted in a mixture
  1015. of cases.  They may be preceded by any number of spaces.  The LIST
  1016. command must be accepted in any of the following forms:
  1017.  
  1018. LIST            (Lists all lines, if any, otherwise does nothing.)
  1019. list 30         (Lists line 30, if it exists.)
  1020. list 25 - 35    (Lists all lines between 25 and 35 inclusive, if any.)
  1021. LIST - 35       (Lists all lines numbered 35 or less, if any.)
  1022. list 25 -       (Lists all lines numbered 25 or more, if any.)
  1023.  
  1024. Furthermore, all spaces are optional in the LIST command provided that
  1025. LIST is written solid, so that LIST25-35 is equivalent to the third
  1026. example above.  Any other forms of LIST should be flagged as an error.
  1027. In particular, all of these should give error messages:
  1028.  
  1029. LIST -
  1030. list 2A
  1031. LIST 30 - 50 -
  1032. list 30 - -50
  1033. list 30-A
  1034. LIST XYZ
  1035.  
  1036. The EXIT command must stand alone; unlike LIST, EXIT is never followed
  1037. by anything.  Except for the LIST and EXIT commands, every line typed
  1038. must begin with a number between 1 and 29999.  (Of course, the user
  1039. should be able to type just a carriage return with no effect.)  LEDIT
  1040. should check that line numbers are in range when adding or replacing
  1041. lines.  The LIST command need not check the range of the line numbers,
  1042. because it should be impossible to create lines with improper numbers.
  1043. Your program need not handle input files so long that 29999 would be
  1044. exceeded when it assigns line numbers starting at 10 with an increment
  1045. of 10.
  1046.  
  1047. Your LEDIT must prompt for input and output file names at the start,
  1048. and it may display a prompt for each line that the user types.  You
  1049. may assume some maximum length for an input line (e.g., 80), and
  1050. assume that no file will have lines longer than the maximum.  You may
  1051. also assume that no file will have special characters like form feeds.
  1052.  
  1053.  
  1054.                            -- continued --
  1055.  
  1056.                                                                Page 24
  1057.  
  1058. For simplicity, there's no way to edit a line except by retyping it.
  1059. Also, there's no way to copy or move a line or a block of lines, and
  1060. no way to delete a block of lines except one line at a time.  There's
  1061. no RENUMBER command.  The user can renumber the entire file starting
  1062. at 10 with an increment of 10 by EXITing and then rerunning LEDIT.
  1063. There's no AUTO command to make the editor type the line numbers
  1064. automatically while text is being typed by the user, and there's no
  1065. means of recovering from a system crash that occurs during an edit.
  1066. Additionally, there's no way to search for a string, or replace one
  1067. string with another.  These features would all be desirable, but we
  1068. feel that Outside Assignment 5 is challenging as it stands.
  1069.  
  1070. You're encouraged to use Ada's "separate" compilation feature, so that
  1071. you don't have to recompile the entire program when developing a
  1072. module.
  1073.  
  1074. As a point of reference, our solution to this assignment consists of
  1075. about 180 lines of code on four pages.  If you have any questions
  1076. about what LEDIT should do, you can compile and run our solution,
  1077. which is in LEDIT.ANS.
  1078.  
  1079. The following declarations are offered by way of suggestion only, and
  1080. you should use them only if you feel comfortable with them:
  1081.  
  1082.      Max_Length : constant Integer := 80;
  1083.      type Text is
  1084.         record
  1085.            Len : Integer range 0 .. Max_Length;
  1086.            Val : String(1 .. Max_Length);
  1087.         end record;
  1088.  
  1089.      type Link;
  1090.      type P is access Link;
  1091.      type Link is
  1092.         record
  1093.            Num  : Positive;
  1094.            Line : Text;
  1095.            Next : P;
  1096.         end record;
  1097.  
  1098.      function Str(T : in Text) return String;
  1099.  
  1100. In our solution, we used type Text as above.  However, we didn't write
  1101. a Text_Handler package, because it didn't seem to be needed.  We used
  1102. a one-page main program with several "separate" subprograms.
  1103.  
  1104.                                                                Page 25
  1105.  
  1106.     STEPS FOR OUTSIDE ASSIGNMENT 5, WRITING A SIMPLE LINE EDITOR
  1107.  
  1108. 1.  Carefully read the requirements starting on page 20 of these
  1109.     notes.  Take your time.
  1110.  
  1111. 2.  Write the Ada code, compile, and link.  Call the main program
  1112.     LEDIT.  If you have any questions about what LEDIT should do, you
  1113.     can compile and run our solution, which is in LEDIT.ANS.
  1114.  
  1115. 3.  Refer to pages 26-28 of these notes for instructions on testing
  1116.     your line editor.  If any tests are failed, go back to step 2.
  1117.  
  1118. 4.  When all the tests are passed, you've completed the assignment and
  1119.     will have a chance to compare your solution with ours.
  1120.  
  1121.                                                                Page 26
  1122.  
  1123.                           HOW TO TEST LEDIT
  1124.  
  1125. 1.  Run LEDIT and give the name of an input file that doesn't exist.
  1126. LEDIT should say "File not found."  Give another name of a file that
  1127. doesn't exist for an output file.
  1128.  
  1129. 2.  Type "LIST" (without the quotes) to make sure that LEDIT can
  1130. handle the LIST command when no text has been entered.
  1131.  
  1132. 3.  Type "EXI".  The program should NOT exit.  If it exits, it's
  1133. probably because the "T" was left in the input buffer from the LIST
  1134. command.  Your program is checking the first four characters of the
  1135. input buffer without checking the length of the typed command.
  1136.  
  1137. 4.  Type "ABC".  The program should display a message about an illegal
  1138. or unrecognized command, or syntax error.
  1139.  
  1140. 5.  Type "0X" (zero followed by X).  The program should reject this
  1141. line, displaying a message about an invalid line number.  Type "0 X".
  1142. The same thing should happen.  Try "30000X", then "30000 X", and then
  1143. "3000000000 X".  The program should reject these, as well.
  1144.  
  1145. 6.  Type "-1 X" and "-1X".  The program should reject these lines,
  1146. displaying a message either about an unrecognized command (or syntax
  1147. error), or an invalid line number.
  1148.  
  1149. 7.  Type a simple carriage return.  There should be no effect, except
  1150. for any prompt being repeated.
  1151.  
  1152. 8.  Type the following exactly as shown.  Note that lines 1000 and 100
  1153. each contain four spaces:
  1154.  
  1155. 30 X
  1156. 1 The
  1157. 29999 ZZZZZZZZ
  1158. 1000    used
  1159. 100    is
  1160. 10000 to test
  1161.    30file --
  1162. 1 This
  1163.     29999 LEDIT.
  1164.  
  1165. 9.  Type "list".  You should see the following, lined up exactly as
  1166. shown.  There should be exactly five spaces for the line numbers.
  1167.  
  1168.     1 This
  1169.    30 file --
  1170.   100    is
  1171.  1000    used
  1172. 10000 to test
  1173. 29999 LEDIT.
  1174.  
  1175.  
  1176.                            -- continued --
  1177.  
  1178.                                                                Page 27
  1179.  
  1180. 10.  Try a line of text beginning with a number: "20000 123 45".  Then
  1181. type "   LIST" with three leading spaces.  You should see
  1182.  
  1183.     1 This
  1184.    30 file --
  1185.   100    is
  1186.  1000    used
  1187. 10000 to test
  1188. 20000 123 45
  1189. 29999 LEDIT.
  1190.  
  1191. 11.  Insert an empty line by typing "15000 ".  Then type "LIST".  You
  1192. should see
  1193.  
  1194.     1 This
  1195.    30 file --
  1196.   100    is
  1197.  1000    used
  1198. 10000 to test
  1199. 15000
  1200. 20000 123 45
  1201. 29999 LEDIT.
  1202.  
  1203. 12.  Type "EXIT ABC".  LEDIT should display a error message and NOT
  1204. exit.  The requirements say that the EXIT command must stand alone.
  1205.  
  1206. 13.  Type "   exit".  LEDIT should exit, and you should have a new
  1207. file with the output file name you gave in step 1.  Type the file with
  1208. the TYPE command.  You should see exactly this, starting in column 1:
  1209.  
  1210. This
  1211. file --
  1212.    is
  1213.    used
  1214. to test
  1215.  
  1216. 123 45
  1217. LEDIT.
  1218.  
  1219. 14.  Run LEDIT again, using for an input file the name of the OUTPUT
  1220. file you specified in step 1.  This time the program should say "File
  1221. found."  Choose yet another name for an output file for this step.
  1222. Type "list".  You should see the following, exactly as shown:
  1223.  
  1224.    10 This
  1225.    20 file --
  1226.    30    is
  1227.    40    used
  1228.    50 to test
  1229.    60
  1230.    70 123 45
  1231.    80 LEDIT.
  1232.  
  1233.                            -- continued --
  1234.  
  1235.                                                                Page 28
  1236.  
  1237. 15.  Type "  LIST 30".  You should see only line 30.  Type
  1238. "list25-45".  You should see only lines 30 and 40.  Type "LIST  - 40".
  1239. You should see lines 10 through 40.  Type "list35 -".  You should see
  1240. lines 40 through 80.  Type "list 15".  The program should either do
  1241. nothing or display a message that line 15 doesn't exist.  Try
  1242. "list 30000" and "list 3000000000".  Again, the program should either
  1243. do nothing or display an error message.  Now type "list" and check
  1244. that the result is the same as in step 14.
  1245.  
  1246. 16.  Try each of the following.  In each case, LEDIT should display an
  1247. error message:
  1248.  
  1249. LIST -
  1250. list 2A
  1251. list 30 - 50 -
  1252. list 30 - -50
  1253.    list 30-A
  1254. LIST XYZ
  1255.  
  1256. 17.  Type "70" to delete line 70.  Type "LIST".  You should see
  1257.  
  1258.    10 This
  1259.    20 file --
  1260.    30    is
  1261.    40    used
  1262.    50 to test
  1263.    60
  1264.    80 LEDIT.
  1265.  
  1266. 18.  Delete line 60.  Do not list.  Now delete line 80 and list.  You
  1267. should see
  1268.  
  1269.    10 This
  1270.    20 file --
  1271.    30    is
  1272.    40    used
  1273.    50 to test
  1274.  
  1275. 19.  Delete line 10 and list.  You should see lines 20 through 50
  1276. above.  Delete line 50 and list.  You should see lines 20 through 40.
  1277. Delete line 30 and list.  You should see lines 20 and 40.  Delete line
  1278. 40 and list.  You should see only line 20.  Delete line 20 and list.
  1279. The result should be the same as in step 2.  Type "EXIT".
  1280.  
  1281. 20.  If your program passed all these tests, sincere congratulations!
  1282. You've completed a difficult assignment.  We hope that you feel
  1283. comfortable with Ada now.  If you like, you can compare your solution
  1284. with ours, starting on page 29 of these notes.  When you go back to
  1285. ADA-TUTR, you'll learn to write your own generic packages, procedures,
  1286. and functions.
  1287.  
  1288.                                                                Page 29
  1289.  
  1290. LEDIT.ANS
  1291. ---------
  1292.  
  1293. -- Our solution to Outside Assignment 5:
  1294. with Text_IO; use Text_IO;
  1295. procedure Ledit is
  1296.    Max_Length      : constant := 80;
  1297.    Max_Line_Number : constant := 29_999;
  1298.    type Text is
  1299.       record
  1300.          Len : Integer range 0 .. Max_Length := 0;
  1301.          Val : String(1 .. Max_Length);
  1302.       end record;
  1303.    type Link;
  1304.    type P is access Link;
  1305.    type Link is
  1306.       record
  1307.          Num  : Positive;
  1308.          Line : Text;
  1309.          Next : P;
  1310.       end record;
  1311.    Head            : P := new Link;
  1312.    Temp            : P;
  1313.    Input_File      : File_Type;
  1314.    Output_File     : File_Type;
  1315.    Input           : Text;
  1316.    Finished        : Boolean := False;
  1317.    Line_Num        : Natural := 10;
  1318.  
  1319.    function  Str(T : in Text) return String is separate;
  1320.    procedure Read_Input_File is separate;
  1321.    procedure Do_Command is separate;
  1322. begin
  1323.    Put("Input file: ");  Get_Line(Input.Val, Input.Len);
  1324.    Read_Input_File;
  1325.    Put("Output file: ");  Get_Line(Input.Val, Input.Len);
  1326.    Create(Output_File, Name => Str(Input));
  1327.  
  1328.    -- Get and process commands.
  1329.    while not Finished loop
  1330.       Put("> ");  Get_Line(Input.Val, Input.Len);
  1331.       Do_Command;
  1332.    end loop;
  1333.  
  1334.    -- Write the output file.
  1335.    Temp := Head.Next;     -- Skip unused link at start of linked list.
  1336.    while Temp /= null loop
  1337.       Put_Line(Output_File, Str(Temp.Line));    -- Write line of text.
  1338.       Temp := Temp.Next;                             -- Get next link.
  1339.    end loop;
  1340.    Close(Output_File);
  1341. end Ledit;
  1342.  
  1343.                            -- continued --
  1344.  
  1345.                                                                Page 30
  1346.  
  1347. separate (Ledit)
  1348. function Str(T : in Text) return String is
  1349. begin
  1350.    return T.Val(1 .. T.Len);
  1351. end Str;
  1352.  
  1353. separate (Ledit)
  1354. procedure Read_Input_File is
  1355. begin   -- If the input file exists, display a message and read it in.
  1356.    Open(Input_File, In_File, Str(Input));
  1357.    Put_Line("File found.");
  1358.    Temp := Head;
  1359.    while not End_Of_File(Input_File) loop
  1360.       Get_Line(Input_File, Input.Val, Input.Len);      -- Read a line.
  1361.       Temp.Next := new Link'(Line_Num, Input, null);   -- Add to list.
  1362.       Temp := Temp.Next;              -- Advance pointer to next link.
  1363.       Line_Num := Line_Num + 10;
  1364.    end loop;
  1365.    Close(Input_File);
  1366. exception  -- If the input file doesn't exist, just display a message.
  1367.    when Name_Error => Put_Line("File not found.");
  1368. end Read_Input_File;
  1369.  
  1370. separate (Ledit)
  1371. procedure Do_Command is
  1372.    procedure Delete_First_Character(T : in out Text) is separate;
  1373.    procedure Get_Leading_Integer(N : out Natural) is separate;
  1374.    procedure Strip_Leading_Spaces_From_Input is separate;
  1375.    procedure Add_Delete_Replace_Line is separate;
  1376.    procedure List is separate;
  1377. begin
  1378.    Strip_Leading_Spaces_From_Input;
  1379.    if Str(Input) = "exit" or Str(Input) = "EXIT" then
  1380.       Finished := True;
  1381.    elsif Input.Len >= 4 and (Input.Val(1 .. 4) = "list" or
  1382.                                Input.Val(1 .. 4) = "LIST") then
  1383.       List;
  1384.    elsif Input.Len > 0 and Input.Val(1) not in '0' .. '9' then
  1385.       Put_Line("Unrecognized command.");
  1386.    elsif Input.Len > 0 then
  1387.       Get_Leading_Integer(Line_Num);
  1388.       if Line_Num not in 1 .. Max_Line_Number then
  1389.          Put_Line("Illegal line number.");
  1390.       else
  1391.          Add_Delete_Replace_Line;
  1392.       end if;
  1393.    end if;
  1394. exception
  1395.    when Numeric_Error | Constraint_Error =>
  1396.       Put_Line("Line number too large.");
  1397. end Do_Command;
  1398.  
  1399.  
  1400.                            -- continued --
  1401.  
  1402.                                                                Page 31
  1403.  
  1404. separate (Ledit.Do_Command)
  1405. procedure Add_Delete_Replace_Line is
  1406.    Inp : Text := Input;
  1407. begin
  1408.    if Inp.Len > 0 and Inp.Val(1) = ' ' then  -- Treat "9x" like "9 x".
  1409.       Delete_First_Character(Inp);
  1410.    end if;
  1411.    Temp := Head;     -- Find where this number belongs in linked list.
  1412.    while Temp /= null and then Temp.Next /= null and then
  1413.                                Temp.Next.Num <= Line_Num loop
  1414.       if Temp.Next.Num = Line_Num then
  1415.          Temp.Next := Temp.Next.Next;                  -- Delete line.
  1416.       else
  1417.          Temp := Temp.Next;           -- Advance to next link in list.
  1418.       end if;
  1419.    end loop;
  1420.    if Input.Len > 0 then                                  -- Add line.
  1421.       Temp.Next := new Link'(Line_Num, Inp, Temp.Next);
  1422.    end if;
  1423. end Add_Delete_Replace_Line;
  1424.  
  1425. separate (Ledit.Do_Command)
  1426. procedure Delete_First_Character(T : in out Text) is
  1427. begin
  1428.    T.Val(1 .. T.Len - 1) := T.Val(2 .. T.LEN);
  1429.    T.Len := T.Len - 1;
  1430. end Delete_First_Character;
  1431.  
  1432. separate (Ledit.Do_Command)
  1433. procedure Get_Leading_Integer(N : out Natural) is
  1434.    Ans: Integer := 0;
  1435. begin
  1436.    while Input.Len > 0 and Input.Val(1) in '0' .. '9' loop
  1437.       Ans := Ans*10 + Character'Pos(Input.Val(1)) -Character'Pos('0');
  1438.       Delete_First_Character(Input);
  1439.    end loop;
  1440.    N := Ans;
  1441. end Get_Leading_Integer;
  1442.  
  1443. separate (Ledit.Do_Command)
  1444. procedure Strip_Leading_Spaces_From_Input is
  1445. begin
  1446.    while Input.Len > 0 and Input.Val(1) = ' ' loop
  1447.       Delete_First_Character(Input);
  1448.    end loop;
  1449. end Strip_Leading_Spaces_From_Input;
  1450.  
  1451.  
  1452.                            -- continued --
  1453.  
  1454.                                                                Page 32
  1455.  
  1456. separate (Ledit.Do_Command)
  1457. procedure List is
  1458.    package IIO is new Integer_IO(Integer); use IIO;
  1459.    Start, Finish : Natural;
  1460.    Valid         : Boolean := True;
  1461. begin
  1462.    Input.Len := Input.Len - 4;      -- Delete the name of the command.
  1463.    Input.Val(1 .. Input.Len) := Input.Val(5 .. Input.Len + 4);
  1464.    Strip_Leading_Spaces_From_Input;
  1465.    if Input.Len = 0 then          -- For "LIST" alone, list all lines.
  1466.       Start := 0;
  1467.       Finish := Max_Line_Number + 1;
  1468.    else
  1469.       Get_Leading_Integer(Start);          -- Get number after "LIST".
  1470.       Strip_Leading_Spaces_From_Input;
  1471.       if Input.Len = 0 then         -- For "LIST n", list only line n.
  1472.          Finish := Start;
  1473.       elsif Input.Val(1) /= '-' then        -- Else "-" must follow n.
  1474.          Valid := False;
  1475.       else
  1476.          Delete_First_Character(Input);             -- Delete the "-".
  1477.          Strip_Leading_Spaces_From_Input;
  1478.          Get_Leading_Integer(Finish);         -- Get number after "-".
  1479.          Strip_Leading_Spaces_From_Input;
  1480.          if Finish = 0 and Start = 0 then     -- "LIST -" isn't valid.
  1481.             Valid := False;
  1482.          elsif Finish = 0 then  -- For "LIST n -", list n through end.
  1483.             Finish := Max_Line_Number + 1;
  1484.          end if;
  1485.          Valid := Valid  and  Input.Len = 0;   -- No trailing garbage.
  1486.       end if;
  1487.    end if;
  1488.    if not Valid then
  1489.       Put_Line("Illegal syntax for LIST.");
  1490.    else
  1491.       Temp := Head.Next;  -- Skip unused link at start of linked list.
  1492.       while Temp /= null and then Temp.Num <= Finish loop
  1493.          if Temp.Num >= Start then
  1494.             Put(Temp.Num, Width => 5);     -- Display line #, width 5.
  1495.             Put_Line(' ' & Str(Temp.Line));   -- Display text of line.
  1496.          end if;
  1497.          Temp := Temp.Next;                          -- Get next link.
  1498.       end loop;
  1499.    end if;
  1500. exception
  1501.    when Numeric_Error | Constraint_Error =>
  1502.       Put_Line("Line number too large in List.");
  1503. end List;
  1504.  
  1505.                                                                Page 33
  1506.  
  1507. TASKING.DUM
  1508. -----------
  1509.  
  1510. with text_io, calendar; use text_io, calendar;
  1511. procedure tasking is
  1512.    interval        : constant duration := 5.0;
  1513.    total_intervals : constant positive := 9;
  1514.    start_time      : constant time := clock;
  1515.    quitting_time   : constant time := start_time +
  1516.                                              total_intervals*interval;
  1517.    next_time       : time := start_time;
  1518.    task type tick is
  1519.       entry make_noise;
  1520.       entry shutdown;
  1521.    end tick;
  1522.    t               : tick;
  1523.    task body tick is
  1524.       quit : boolean := false;
  1525.    begin
  1526.       while not quit loop
  1527.          select
  1528.             accept make_noise do
  1529.                put_line("Tick!");
  1530.             end make_noise;
  1531.          or
  1532.             accept shutdown;
  1533.             quit := true;
  1534.          end select;
  1535.       end loop;
  1536.    end tick;
  1537. begin
  1538.    while next_time < quitting_time loop
  1539.       t.make_noise;
  1540.       next_time := next_time + interval;
  1541.       put_line("(5-second delay)"); delay next_time - clock;
  1542.    end loop;
  1543.    t.shutdown;
  1544. end tasking;
  1545.  
  1546.                                                                Page 34
  1547.  
  1548.          STEPS FOR OUTSIDE ASSIGNMENT 6, EXERCISE IN TASKING
  1549.  
  1550. 1.  Make a copy of TASKING.DUM by typing COPY TASKING.DUM TASKING.ADA.
  1551.     Compile, link, and execute the program to make sure it displays
  1552.     "Tick!" nine times, with a 5-second delay after each "Tick."
  1553.  
  1554. 2.  Edit TASKING.ADA to become your solution.  Make your changes in
  1555.     upper case.
  1556.  
  1557. 3.  Compile TASKING.ADA, link, and execute.
  1558.  
  1559. 4.  Compare your output with page 35 of these notes.  If there are any
  1560.     errors, go back to step 2.
  1561.  
  1562. 5.  When your output agrees with these notes, you've finished the
  1563.     assignment and will have a chance to compare your solution with
  1564.     ours.
  1565.  
  1566.                                                                Page 35
  1567.  
  1568.       OUTPUT FROM TASKING.EXE AFTER MODIFICATION OF TASKING.ADA
  1569.  
  1570. C>tasking
  1571. Task number 1 is starting.
  1572. Task number 2 is starting.
  1573. Task number 3 is starting.
  1574. (5-second delay)
  1575. (5-second delay)
  1576. Task number 1 is starting.
  1577. (5-second delay)
  1578. Task number 2 is starting.
  1579. (5-second delay)
  1580. Task number 1 is starting.
  1581. Task number 3 is starting.
  1582. (5-second delay)
  1583. (5-second delay)
  1584. Task number 1 is starting.
  1585. Task number 2 is starting.
  1586. (5-second delay)
  1587. (5-second delay)
  1588. Task number 1 is starting.
  1589. Task number 3 is starting.
  1590. (5-second delay)
  1591.  
  1592. C>
  1593.  
  1594.                                                                Page 36
  1595.  
  1596. TASKING.ANS
  1597. -----------
  1598.  
  1599. -- Our solution to Outside Assignment 6:
  1600. with text_io, calendar; use text_io, calendar;
  1601. procedure tasking is
  1602.    interval        : constant duration := 5.0;
  1603.    total_intervals : constant positive := 9;
  1604.    start_time      : constant time := clock;
  1605.    quitting_time   : constant time := start_time +
  1606.                                              total_intervals*interval;
  1607.    next_time       : time := start_time;
  1608.    task type tick is
  1609.       ENTRY IDENTIFY(TASK_NUMBER : IN NATURAL);
  1610.       entry shutdown;
  1611.    end tick;
  1612.    T               : ARRAY(1 .. 3) OF TICK;
  1613.    PERIOD          : CONSTANT ARRAY(T'RANGE) OF POSITIVE := (2, 3, 4);
  1614.    TIMER           : ARRAY(T'RANGE) OF NATURAL := (OTHERS => 0);
  1615.    task body tick is
  1616.       quit : boolean := false;
  1617.    begin
  1618.       while not quit loop
  1619.          select
  1620.             ACCEPT IDENTIFY(TASK_NUMBER : IN NATURAL) DO
  1621.                PUT_LINE("Task number" & INTEGER'IMAGE(TASK_NUMBER) &
  1622.                     " is starting.");
  1623.             END IDENTIFY;
  1624.          or
  1625.             accept shutdown;
  1626.             quit := true;
  1627.          end select;
  1628.       end loop;
  1629.    end tick;
  1630. begin
  1631.    while next_time < quitting_time loop
  1632.       FOR I IN T'RANGE LOOP
  1633.          IF TIMER(I) = 0 THEN
  1634.             T(I).IDENTIFY(I);
  1635.             TIMER(I) := PERIOD(I);
  1636.          END IF;
  1637.          TIMER(I) := TIMER(I) - 1;
  1638.       END LOOP;
  1639.       next_time := next_time + interval;
  1640.       put_line("(5-second delay)"); delay next_time - clock;
  1641.    end loop;
  1642.    FOR I IN T'RANGE LOOP
  1643.       T(I).SHUTDOWN;
  1644.    END LOOP;
  1645. end tasking;
  1646.  
  1647.                                                                Page 37
  1648.  
  1649.   APPENDIX A:  WOULD YOU LIKE A TEXTBOOK TO USE ALONG WITH ADA-TUTR?
  1650.  
  1651. ADA-TUTR doesn't require a textbook, but a number of users have asked
  1652. us to recommend a book that would go well with this course.  We made a
  1653. special arrangement with John Wiley and Sons so that you can buy the
  1654. excellent textbook RENDEZVOUS WITH ADA by David Naiditch for only
  1655. $44.95 plus sales tax.  Simply print the file COUPON.TXT, or copy the
  1656. coupon below.  Please send it to the address on the coupon, not to
  1657. Software Innovations Technology.
  1658.  
  1659. +--------------------------------------------------------------------+
  1660. |                                                                    |
  1661. | If you would like to have a textbook to go along with ADA-TUTR,    |
  1662. | send this coupon to                                                |
  1663. |                                                                    |
  1664. |                   Attn.: Jane Andolsek, 4th floor                  |
  1665. |                       Wiley - Training Sales                       |
  1666. |                        John Wiley and Sons                         |
  1667. |                          605 Third Avenue                          |
  1668. |                        New York, NY  10158                         |
  1669. |                                                                    |
  1670. | Please send me ______ copy(ies) of RENDEZVOUS WITH ADA by David    |
  1671. | Naiditch, to examine for 15 days.                                  |
  1672. |                                                                    |
  1673. | Order #: 1-61654-0.  Price: $44.95 plus local sales tax, postage   |
  1674. | and handling.                                                      |
  1675. |                                                                    |
  1676. | [ ]  Bill me.                                                      |
  1677. |                                                                    |
  1678. | [ ]  Payment enclosed.  (Orders accompanied by payment will be     |
  1679. |      sent postpaid.)                                               |
  1680. |                                                                    |
  1681. | [ ]  Charge my   ___ VISA   ___ MasterCard   ___ American Express  |
  1682. |      (Note: Credit card orders are not considered prepayment.)     |
  1683. |                                                                    |
  1684. |      Account #: ________________________________                   |
  1685. |                                                                    |
  1686. |      Expiration Date: __________________________                   |
  1687. |                                                                    |
  1688. | NAME:____________________________ AFFILIATION:____________________ |
  1689. |                                                                    |
  1690. | ADDRESS:__________________________________________________________ |
  1691. |                                                                    |
  1692. | CITY/STATE/ZIP:_____________________ SIGNATURE:___________________ |
  1693. |                                  (Offer invalid without signature) |
  1694. |                                                                    |
  1695. | (Prices subject to change without notice and higher outside the    |
  1696. | U.S.A.)                                                            |
  1697. |                                                                    |
  1698. +--------------------------------------------------------------------+
  1699.  
  1700.                                                                Page 38
  1701.  
  1702.           APPENDIX B:  RUNNING BOOK TO PRINT ALL THE SCREENS
  1703.  
  1704. If you're running ADA-TUTR on a PC, you can always print the screen
  1705. that's currently being displayed by holding a Shift key while pressing
  1706. the PrtSc key.
  1707.  
  1708. However, several users wanted to be able to print ALL the screens in
  1709. the entire course, as one large book.  So, starting with version 2.0
  1710. of ADA-TUTR, we added the program BOOK.  This program reads the file
  1711. ADA_TUTR.DAT and produces two large output files, which can then be
  1712. printed.  Be prepared to print about 500 pages!
  1713.  
  1714. Simply type BOOK to run the program.
  1715.  
  1716.  
  1717. BOOK creates plain ASCII files, double spaced the way this paragraph
  1718.                                 -------------
  1719. is double spaced.  It emphasizes text by placing hyphens below the
  1720.    -------------      ----------                 -------
  1721. lines like this.
  1722.       ---------
  1723.  
  1724.  
  1725. BOOK asks you for the name of the output file for the first half of
  1726. the tutorial.  After that file is written, BOOK asks for the name of
  1727. the output file for the second half of the tutorial.  You can then
  1728. print the output files.
  1729.  
  1730. You can optionally specify the name PRN for both output files, to have
  1731. the output of BOOK go directly to the printer.
  1732.  
  1733. Begin reading your printed output with screen 104.  Note that, at the
  1734. bottom of each page, there's a list of possible user responses with
  1735. screen numbers.  For example, at the bottom of Screen 104 you'll see
  1736.  
  1737.   'Y' 107  'N' 122
  1738.  
  1739. This means that, if the user presses Y, screen 107 will be shown next,
  1740. and if the user presses N, screen 122 will be next.  Pressing X always
  1741. takes the user to screen 103.  The special "screen numbers" 098
  1742. through 100 appearing at the bottom of screens 107 and 108 are
  1743. explained in the introductory comments in ADA_TUTR.ADA.
  1744.  
  1745. BOOK, like ADA-TUTR, will run on a PC or on any Ada-speaking computer.
  1746.  
  1747.                                                                Page 39
  1748.  
  1749.          APPENDIX C:  SOME ADA COMPILERS AVAILABLE FOR THE PC
  1750.  
  1751. Here's a brief list of Ada compilers available for the IBM PC and
  1752. compatibles.  For this course, an Ada compiler is helpful, but not
  1753. required.  There are six Outside Assignments; most of them ask you to
  1754. write and compile a short Ada program.  If you don't have access to an
  1755. Ada compiler, just skip the Outside Assignments.
  1756.  
  1757. Although we may now have a small financial interest in some of the
  1758. companies mentioned here (see page 5), we try to keep this list
  1759. unbiased.  If you know of an Ada compiler for the PC that should be on
  1760. this list, or if you have any updated information or corrections,
  1761. please contact us.
  1762.  
  1763. 1.  At the low end of the scale is Augusta.  This compiler is in the
  1764.     public domain, and can be found on many computer bulletin boards.
  1765.     It's a very small subset of Ada with no packages.  It translates
  1766.     Ada to a P-code, and then interprets the P-code.  Some of the
  1767.     syntax is non-standard, such as "elseif" where Ada uses "elsif."
  1768.     Older versions of Augusta require Turbo Pascal.  Augusta isn't
  1769.     really adequate for most of the Outside Assignments of ADA-TUTR.
  1770.  
  1771. 2.  Janus/Ada is sold by R R Software, Inc., Box 1512, Madison, WI
  1772.     53701, phone 800-722-3248, starting at $129.  Educational
  1773.     discounts are available.  A complete development system with tools
  1774.     (such as a debugger) and utility packages is available for $500,
  1775.     but it requires an 80386 computer.  Janus/Ada is validated and
  1776.     produces native PC code; no interpreter is required.
  1777.  
  1778. 3.  IntegrAda is sold by Aetech, Inc., 5841 Edison Place, Suite 110,
  1779.     Carlsbad, CA 92008, phone 619-431-7714, starting at $195.
  1780.     Students can obtain the IntegrAda Student Package, which includes
  1781.     IntegrAda and learning tools, starting at $89.  IntegrAda includes
  1782.     CASE (Computer-Aided Software Engineering) tools and utility
  1783.     packages.  It's validated and produces native PC code; no
  1784.     interpreter is required.
  1785.  
  1786. 4.  Open Ada DOS is sold by Meridian Software Systems, Inc., 10
  1787.     Pasteur St., Irvine, CA 92718, phone 800-221-2522 (in CA,
  1788.     714-727-0700), starting at $249 ($99 for students).  Open Ada DOS
  1789.     includes tools (such as a debugger) and utility packages.  It's
  1790.     validated and produces native PC code; no interpreter is required.
  1791.  
  1792. 5.  At the high end of the scale is FirstAda, sold by Alsys, Inc., 67
  1793.     South Bedford St., Burlington, MA 01803-9748, phone 617-270-0030.
  1794.     The price is $595.  FirstAda is validated and requires a PC/AT (or
  1795.     compatible) with at least 2 MB of extended memory.  However, it
  1796.     can produce native code for the PC/XT; no interpreter is required.
  1797.  
  1798.                                                                Page 40
  1799.  
  1800.             APPENDIX D:  SAMPLE MULTI-USER SOFTWARE LICENSE
  1801.  
  1802. Software Innovations Technology believes in a plain-English software
  1803. license that people can understand.  A sample license appears on the
  1804. next page.  However, if your company's lawyers would prefer a
  1805. differently worded license, simply contact us.  We'll be happy to
  1806. accommodate you.
  1807.  
  1808. As you can see, the terms of our license are very generous.  We allow
  1809. you to make as many copies of ADA-TUTR as you like, and to install it
  1810. on as many computers as you like, regardless of the computer type
  1811. (laptop, desktop, workstation, mainframe, etc.)  Also, you may use
  1812. ADA-TUTR at all your geographical locations, which is why we use the
  1813. term Multi-User License rather than Site License.  The only thing we
  1814. limit is the total number of people who may use ADA-TUTR (except in
  1815. the case of an unlimited license).  Please remember that if 100 people
  1816. use ADA-TUTR now and 100 others use it later, that counts as 200
  1817. users, not 100.
  1818.  
  1819. In the sample license on the next page, comments appear in brackets.
  1820. These comments are not part of the actual license.
  1821.  
  1822.                                                                Page 41
  1823.  
  1824.                  [SAMPLE] MULTI-USER SOFTWARE LICENSE
  1825.  
  1826.                     Software Innovations Technology
  1827.                         1083 Mandarin Drive NE
  1828.                        Palm Bay, FL  32905-4706
  1829.                             (407) 951-0233
  1830.  
  1831.  
  1832.    This license conveys to XYZ Company the right to use the comput-
  1833.    er program  ADA-TUTR, the Interactive Ada Tutor,  under the fol-
  1834.    lowing conditions:
  1835.  
  1836.    1.  The program shall remain  the property of  Software  Innova-
  1837.    tions Technology.
  1838.  
  1839.    2.  The program may be freely copied and installed on any or all
  1840.    computers of  XYZ Company,  regardless of geographical location.
  1841.    Copies of the program may be distributed outside XYZ Company for
  1842.    others to evaluate on a trial basis.
  1843.  
  1844.    3.  This license is perpetual.
  1845.  
  1846.    4.  The number of  XYZ Company  personnel [or "students and per-
  1847.    sonnel of XYZ University"] who may use the program is unlimited.
  1848.                              [*** OR ***]
  1849.    4.  The total number of XYZ Company personnel  [or "students and
  1850.    personnel of  XYZ  University"]  who use the program,  excluding
  1851.    those who only briefly evaluate it, shall not exceed  two  thou-
  1852.    sand (2000)  [or "five hundred (500)"  or  "one hundred (100)"].
  1853.    In calculating the number of users,  XYZ Company must always add
  1854.    the number of people  currently  using the program to the number
  1855.    who have used it in the past.
  1856.  
  1857.    5.  [This paragraph is omitted in unlimited licenses.]  Software
  1858.    Innovations Technology  sells  licenses  for  larger  numbers of
  1859.    users.  XYZ Company may, at any time, upgrade this license for a
  1860.    larger number of users by paying,  to Software Innovations Tech-
  1861.    nology, the difference in price between the two licenses.
  1862.  
  1863.    6.  This license is not transferable.
  1864.  
  1865.    7.  The Disclaimer of Warranty, included in the program documen-
  1866.    tation, applies as if included in this license.
  1867.  
  1868.    8.  [This paragraph is  omitted  if the order is prepaid.]  This
  1869.    license shall be  void  if the invoice is not paid within thirty
  1870.    (30) days of the date of this license.
  1871.  
  1872.  
  1873.    (Signed)________________________________  Date _________________
  1874.  
  1875.            John J. Herro, President
  1876.            Software Innovations Technology
  1877.  
  1878.                                                                Page 42
  1879.  
  1880.          APPENDIX E:  INSTALLING ADA-TUTR ON OTHER COMPUTERS
  1881.  
  1882. Because source code is included with ADA-TUTR, you can install
  1883. ADA-TUTR on almost any computer that has an Ada compiler - from
  1884. compact units to large mainframes.  ADA-TUTR is written in Ada (of
  1885. course!), and Ada programs tend to be very portable.
  1886.  
  1887. The screen should have at least 24 rows of 80 characters each, and
  1888. should support the ANSI escape sequences for highlighting, reverse
  1889. video, cursor positioning, etc.  Almost all computers qualify.
  1890.  
  1891. You need a way to send text files from your PC to the other computer.
  1892. Files are usually sent to large mainframes with the program KERMIT,
  1893. which is in the public domain.  One version of KERMIT runs on the PC,
  1894. another on the mainframe.  The two communicate with each other.
  1895. Sometimes XMODEM or another protocol is used instead of KERMIT.
  1896.  
  1897. If a communications program is available on the PC but not on the
  1898. other computer, you can still send text files, but not as efficiently.
  1899. Connect your PC as a terminal and tell the other computer to copy the
  1900. keyboard to a new file.  For example, on a VAX computer running VMS,
  1901. the command is "COPY TT: filename.ext" (without the quotes).  Then
  1902. tell your communications program to send (or "upload") the file, using
  1903. ASCII protocol, and stripping line feeds.  After the file is sent,
  1904. type the appropriate end-of-file character for the other computer.  On
  1905. a VAX running VMS, you would type Control-Z.  Since this method of
  1906. file transfer doesn't do error checking, you may have to send each
  1907. file twice using two different names, and compare the two files with
  1908. each other on the other computer.  It's far better to use a
  1909. communications program on the other computer, if one is available.
  1910.  
  1911. OK, you have some means of sending text files.  You won't have to send
  1912. other kinds of files.  To install ADA-TUTR on the other computer, just
  1913. follow these steps:
  1914.  
  1915. 1.  Type DAT2TXT on the PC.  This will read the file ADA_TUTR.DAT,
  1916. which is not a text file, and create a new text file TUTOR.TXT, which
  1917. can be sent to the other computer.  DAT2TXT will probably take several
  1918. minutes to run.  Don't try to bypass this step even if you're able to
  1919. send non-text files.  It's important that you send TUTOR.TXT and not
  1920. ADA_TUTR.DAT, because the PC version of ADA_TUTR.DAT doesn't work on
  1921. some systems.
  1922.  
  1923. 2.  Decide where ADA-TUTR will reside on the other computer, so that
  1924. it will be available to all users.  For example, on a VAX computer
  1925. running VMS, the tutor is usually placed in SYS$INSTRUCTION.  It could
  1926. also be placed in SYS$MANAGER, etc.
  1927.  
  1928.                            -- continued --
  1929.  
  1930.                                                                Page 43
  1931.  
  1932. 3.  Send to the other computer all the files that come with ADA-TUTR,
  1933. except ADA_TUTR.DAT and the files ending in .EXE.  Be sure to send
  1934. TUTOR.TXT, created in step 1.  Don't try to send ADA_TUTR.DAT and the
  1935. .EXE files, because they're not text files.  Also note that ADA-TUTR
  1936. creates a file ADA_TUTR.USR the first time it's run.  Do NOT send that
  1937. file, because it also is not a text file.  If our file names are
  1938. illegal on the other system, you'll have to rename them as they're
  1939. sent.  (We haven't seen a system where our file names are illegal.)
  1940.  
  1941. 4.  If any of the file names ADA_TUTR.DAT, ADA_TUTR.USR, or TUTOR.TXT
  1942. are illegal on your system, edit the files ADA_TUTR.ADA, BOOK.ADA,
  1943. CHANGESN.ADA, and TXT2DAT.ADA to show new, legal file names.  Search
  1944. for the old file names and replace them with the new ones.
  1945.  
  1946. 5.  Note that each user will probably run ADA-TUTR from his or her own
  1947. file directory.  There will be a file ADA_TUTR.USR in each user's
  1948. directory, but all the other files will reside in a common area, such
  1949. as SYS$INSTRUCTION, etc.  Therefore, edit the files ADA_TUTR.ADA,
  1950. BOOK.ADA, CHANGESN.ADA, and TXT2DAT.ADA to show the full path name of
  1951. the file ADA_TUTR.DAT.  On a VAX system, for example, you might search
  1952. for the name ADA_TUTR.DAT and replace it with
  1953. SYS$INSTRUCTION:ADA_TUTR.DAT.
  1954.  
  1955. 6.  On one system we encountered, Ada source file names must end in .a
  1956. rather than .ADA.  If that's the case on your system, rename all the
  1957. .ADA files.
  1958.  
  1959. 7.  On the other computer, compile, link, and run TXT2DAT.ADA.  Some
  1960. systems call the linking step "binding."  This program will read
  1961. TUTOR.TXT and create ADA_TUTR.DAT on the other system.  If you wish,
  1962. you may then delete TUTOR.TXT.
  1963.  
  1964. 8.  If you're using VAX Ada, skip to page 45.  If you're using a UNIX
  1965. based system that has a C compiler with the ability to link into Ada
  1966. programs, skip to page 46.  Otherwise, continue with the next page.
  1967. If you're not certain, continue with the next page.
  1968.  
  1969.                            -- continued --
  1970.  
  1971.                                                                Page 44
  1972.  
  1973.  
  1974. 9.  Compile VANILLA.ADA, but don't try to link or run it.  This "plain
  1975. vanilla" file will work with any standard Ada compiler.
  1976.  
  1977. 10.  Compile ADA_TUTR.ADA.
  1978.  
  1979. 11.  Link, giving the name of the main program, ADA_TUTR.  This will
  1980. produce an executable file, which on most systems will be called
  1981. ADA_TUTR.EXE.  However, on a few systems the executable file will have
  1982. a strange name, so rename the executable file if necessary.
  1983.  
  1984. 12.  Run ADA-TUTR.  The command is usually ADA_TUTR or RUN ADA_TUTR.
  1985. Note that, on some systems, you'll have to strike ENTER (or RETURN or
  1986. NEW-LINE) after each response, even though the program says, "You need
  1987. not hit ENTER."  The reason is that some systems require you to strike
  1988. ENTER when they read the keyboard through TEXT_IO.  However, with
  1989. recent versions of TeleGen Ada, you don't have to hit ENTER.  Also
  1990. note that some of the tutorial text refers to commands that are meant
  1991. for a PC, such as COPY and PRINT.  These commands may have to be
  1992. varied slightly to work on your system.
  1993.  
  1994. 13.  Define a command so that each user will be able to run ADA-TUTR
  1995. easily.
  1996.  
  1997.  
  1998. We'll be happy to help you install ADA-TUTR and get it running, even
  1999. if you haven't registered or bought a license.  We want you to try
  2000. ADA-TUTR before paying for it.
  2001.  
  2002.                                                                Page 45
  2003.  
  2004.                    SPECIAL INSTRUCTIONS FOR VAX ADA
  2005.  
  2006. 9.  If you're using VAX Ada, compile VAX.ADA, but don't try to link or
  2007. run it.  The file VANILLA.ADA would work, but VAX.ADA makes it
  2008. unnecessary to strike RETURN after each response.  The reason is that
  2009. VAX.ADA gets characters from the keyboard by calling the System
  2010. Service routines, without going through TEXT_IO.
  2011.  
  2012. 10.  Compile ADA_TUTR.ADA.
  2013.  
  2014. 11.  Link, giving the name of the main program, ADA_TUTR.  The command
  2015. is ACS LINK ADA_TUTR.  This will produce an executable file,
  2016. ADA_TUTR.EXE.
  2017.  
  2018. 12.  Run ADA-TUTR by typing RUN ADA_TUTR.  Note that some of the
  2019. tutorial text refers to commands that are meant for a PC, such as COPY
  2020. and PRINT.  These commands may have to be varied slightly to work on
  2021. your system.  For example, when the text says to type
  2022. COPY TRITYPE.DUM TRITYPE.ADA, your users might have to type
  2023. COPY SYS$INSTRUCTION:TRITYPE.DUM TRITYPE.ADA.
  2024.  
  2025. 13.  Define a command so that each user will be able to run ADA-TUTR
  2026. easily.  For example, you might add the following line to SYLOGIN.COM:
  2027.  
  2028.             $ TEACHADA :== "RUN SYS$INSTRUCTION:ADA_TUTR"
  2029.  
  2030.  
  2031. We'll be happy to help you install ADA-TUTR and get it running, even
  2032. if you haven't registered or bought a license.  We want you to try
  2033. ADA-TUTR before paying for it.
  2034.  
  2035.                                                                Page 46
  2036.  
  2037.              SPECIAL INSTRUCTIONS FOR UNIX BASED SYSTEMS
  2038.  
  2039. 9.  If you're using a UNIX based system with a C compiler, and your
  2040. Ada compiler can link with modules produced by C, compile ONECHAR.C
  2041. with the C compiler.  If you can't compile ONECHAR.C because your
  2042. system doesn't have the include file TERMIO.H, then compile ALTCHAR.C
  2043. instead.  However, if you compile ALTCHAR.C, you'll have to invoke
  2044. ADA-TUTR between two calls to stty, in a script file.  For example:
  2045.                      stty raw
  2046.                      /usr/local/ada-tutr/ada_tutr
  2047.                      stty -raw
  2048.  
  2049. 10.  Compile UNIX.ADA, but don't try to link or run it.  The file
  2050. VANILLA.ADA would work, but UNIX.ADA, when used with ONECHAR.C or
  2051. ALTCHAR.C, makes it unnecessary to strike RETURN after each response.
  2052. The reason is that ONECHAR.C and ALTCHAR.C get characters directly
  2053. from the keyboard, without going through TEXT_IO.
  2054.  
  2055. 11.  Compile ADA_TUTR.ADA.
  2056.  
  2057. 12.  Link, giving the name of the main program, ADA_TUTR.  Include the
  2058. object file from the C compiler in the link.  This will create an
  2059. executable file, called ADA_TUTR on most systems.  (On one system we
  2060. encountered, the file created was named a.out.)  If necessary, rename
  2061. the executable file to an appropriate name, such as ada_tutr or
  2062. ADA_TUTR or ADA_TUTR.EXE.
  2063.  
  2064.  
  2065. Here are sample steps 9 through 12 for two UNIX based systems:
  2066.  
  2067.        ON A UNISYS 5000/80:             ON A HARRIS HCX:
  2068.  
  2069.        cc -c onechar.c                  cc -c onechar.c
  2070.        ada unix.ada ada_tutr.ada        ada unix.a ada_tutr.a
  2071.        ald -p'onechar' ada_tutr         a.ld ada_tutr onechar.o
  2072.                                         mv a.out ada_tutr
  2073.  
  2074.  
  2075. 13.  Run ADA-TUTR.  Usually this is done by typing ada_tutr.  Note
  2076. that some of the tutorial text refers to commands that are meant for a
  2077. PC, such as COPY and PRINT.  These commands may have to be varied
  2078. slightly to work on your system.
  2079.  
  2080. 14.  Define a command so that each user will be able to run ADA-TUTR
  2081. easily.
  2082.  
  2083.  
  2084. We'll be happy to help you install ADA-TUTR and get it running, even
  2085. if you haven't registered or bought a license.  We want you to try
  2086. ADA-TUTR before paying for it.
  2087.  
  2088.                                                                Page 47
  2089.  
  2090.           APPENDIX F:  WE LISTEN!  NEW FEATURES OF ADA-TUTR
  2091.  
  2092. Almost all of the features added to ADA-TUTR were done as a result of
  2093. your comments and suggestions.  Thank you very much, and please
  2094. continue to send them!  We want to produce the very best Ada Tutor
  2095. possible.  Here's a history of revisions to ADA-TUTR.  In addition to
  2096. the changes shown here, we're constantly making minor improvements in
  2097. the tutorial text and updating the list of Ada compilers available for
  2098. the PC (page 39).
  2099.  
  2100.  
  2101. VERSION 3.00:
  2102.  
  2103. Added much new material to cover Ada 9X, and changed the
  2104. capitalization style of all Ada code from that of the Ada 83 LRM to
  2105. that of the Ada 9X LRM.
  2106.  
  2107. Removed references to PC-Write, because recent versions of DOS include
  2108. a screen editor.
  2109.  
  2110. Replaced JANUS.ADA with JANUS16.PKG and JANUS32.PKG.
  2111.  
  2112.  
  2113. VERSION 2.02:
  2114.  
  2115. Added the files DESC.SDI and FILE_ID.DIZ, briefly describing ADA-TUTR.
  2116.  
  2117. Improved ED.ADA to take advantage of the newest version PC-Write,
  2118. called PC-Write Advanced Level.
  2119.  
  2120.  
  2121. VERSION 2.01:
  2122.  
  2123. Added the file JANUS.ADA.
  2124.  
  2125.  
  2126. VERSION 2.00:
  2127.  
  2128. Changed the ADA_TUTR.DAT file to a more compact format, so that
  2129. ADA-TUTR would take less room on a hard disk and be able to run from a
  2130. floppy diskette.
  2131.  
  2132. Added the BOOK program to print all of the tutorial screens as a large
  2133. book (page 38).
  2134.  
  2135. Updated Outside Assignment 6 to make it easier to see where the
  2136. 5-second intervals occur.
  2137.  
  2138. Added the sample Multi-User License (pages 40-41).
  2139.  
  2140. Added the special offer for a textbook (page 37).
  2141.  
  2142. VERSION 1.22:
  2143.  
  2144. Added ALTCHAR.C for UNIX based systems that don't have the file
  2145. TERMIO.H.  (Thank you, Mr. Richard Conn, 22 Hunt Court, Tinton Falls,
  2146. NJ 07753.)
  2147.                                                                Page 48
  2148.  
  2149. VERSION 1.21:
  2150.  
  2151. Added ONECHAR.C so users of UNIX based systems wouldn't have to strike
  2152. ENTER after each response.  (Thank you, Mr. David Hill, 7549 Wynford
  2153. Street, Salt Lake City, UT 84121.)
  2154.  
  2155. Changed all hyphens in file names to underlines, at the request of
  2156. PC-SIG, so that ADA-TUTR would be compatible with High Sierra Format
  2157. CD-ROMs.
  2158.  
  2159.  
  2160. VERSION 1.20:
  2161.  
  2162. Added the ability to select background, foreground, and border colors
  2163. on a PC without sacrificing compatibility with mainframe computers and
  2164. monochrome PCs.
  2165.  
  2166. Made ADA-TUTR automatically remember where you leave off when you exit
  2167. the program, so that you don't have to write down the screen number.
  2168. Also made ADA-TUTR remember your color choices.
  2169.  
  2170. Made ADA-TUTR tell you the current screen number and the approximate
  2171. percentage through the course when you strike X, and added the ability
  2172. to go back to the last question or to the last Outside Assignment.
  2173.  
  2174. Added a special screen at the start of each major section, showing an
  2175. outline of the course.
  2176.  
  2177. Updated the tutorial text to reflect the government's new policy
  2178. regarding expiration of Validation Certificates.
  2179.  
  2180. Updated the tutorial text to show that the newest Ada compilers now
  2181. raise CONSTRAINT_ERROR where NUMERIC_ERROR was once raised.
  2182.  
  2183. Added the offer for customized versions of ADA-TUTR, and for the
  2184. Customization Kit (page 4).
  2185.  
  2186. Recompiled ADA-TUTR using a validated compiler from Meridian Software
  2187. Systems, Inc., instead of an older unvalidated compiler from Artek,
  2188. Inc.
  2189.  
  2190. Made ADA-TUTR available on 3.5" as well as 5.25" diskettes.
  2191.  
  2192.  
  2193. VERSION 1.01:
  2194.  
  2195. Fixed minor typographical errors in Version 1.00.
  2196.  
  2197.                                                                Page 49
  2198.  
  2199.                  APPENDIX G:  DISCLAIMER OF WARRANTY
  2200.  
  2201. We hate legal mumbo jumbo, but we have to say the following to protect
  2202. ourselves:
  2203.  
  2204. Software Innovations Technology makes no warranty of any kind,
  2205. expressed or implied, including any warranties of merchantability or
  2206. fitness for a particular purpose.  We shall not be liable for any
  2207. damages, whether direct, indirect, incidental, special, or
  2208. consequential, arising from a failure of this program to operate in a
  2209. manner desired by the user.  We shall not be liable for any damage to
  2210. data or property which may be caused directly or indirectly by use of
  2211. this program.  IN NO EVENT SHALL SOFTWARE INNOVATIONS TECHNOLOGY BE
  2212. LIABLE FOR ANY DAMAGES, INCLUDING ANY LOST PROFITS, LOST SAVINGS, OR
  2213. OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  2214. INABILITY TO USE THIS PROGRAM, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  2215.